package com.etc.colldemo;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.TreeSet;

/**
 * @author: knowno
 * @create: 2024-09-10 15:05
 * @Version 1.0
 **/
public class EmployeeTreeSet {
    public static void main(String[] args) {

        //创建一个TreeSet对象
        TreeSet<Employee> treeSet = new TreeSet<Employee>();

        //添加元素
        Employee employee1 = new Employee(1,"A","开发工程师",42345);
        Employee employee2 = new Employee(4,"D","开发工程师",12346);
        Employee employee3 = new Employee(5,"E","开发工程师",12349);
        Employee employee4 = new Employee(3,"C","开发工程师",22345);
        Employee employee5 = new Employee(2,"B","开发工程师",32345);

        // Exception in thread "main" java.lang.ClassCastException: com.etc.colldemo.Employee cannot be cast to java.lang.Comparable
        treeSet.add(employee1);
        treeSet.add(employee2);
        treeSet.add(employee3);
        treeSet.add(employee4);
        treeSet.add(employee5);

        for (Employee employee : treeSet) {
            System.out.println(employee);
        }
    }
}
